// pages/ordersuccess/index.js
const app = getApp();

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		active_type: '',
		courseId: '',
		course:{}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		if(options.active_type) {
			this.setData({
				active_type: options.active_type,
				courseId: options.courseId
			})

			this.getDetail();
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
		let course = this.data.course;
		let that = this;
		return {
			title: course.crowdfunding ? course.crowdfunding.title : course.courseName,
			imageUrl: course.uploadImg,
			path: '/pages/classdetail/index?courseId'+that.data.courseId+'&active_type=crowdfunding'
		}
	},
	backFn: function() {
		wx.switchTab({
			url: '/pages/index/index',
		})
	},
	getDetail(){
		let that = this;
		app.request({
			url: 'course/detail',
			data: {
				course_id: that.data.courseId
			},
			sCallback: (res) => {
				if(res.code == 1) {
					that.setData({
						course:res.data
					})
				}
			}
		})
	}
})
